package com.park.dailytool.controller;

import com.park.dailytool.base.AjaxResult;
import com.park.dailytool.base.poi.ExcelUtil;
import com.park.dailytool.data.pojo.model.local.OrderPay;
import com.park.dailytool.enums.OrderType;
import com.park.dailytool.service.LinHaiAmountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.time.LocalDate;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huangding
 * @description
 * @date 2019/1/23 13:22
 */
@RestController
@RequestMapping("linhai/amount")
@Api("财务数据处理")
@Slf4j
public class LinHaiAmountController {

    @Autowired
    private LinHaiAmountService linHaiAmountService;



    @ApiOperation(value = "获取时间段的充值Excel文件", notes = "开始时间需大于结束时间", produces = "application/octet-stream")
    @GetMapping("recharge")
    public AjaxResult rechargeExcel(
        @ApiParam(value = "开始时间", format = "2019-01-01") @RequestParam String startCreated,
        @ApiParam(value = "结束时间", format = "2019-01-01") @RequestParam String endCreated,
        HttpServletRequest request,
        HttpServletResponse response) {

        List<OrderPay> list = linHaiAmountService
            .getOrderListByType(OrderType.DISCOUNT.getCode(),
                LocalDate.parse(startCreated).atStartOfDay(),
                LocalDate.parse(endCreated).atStartOfDay());

        ExcelUtil<OrderPay> util = new ExcelUtil<>(OrderPay.class);
        util.exportExcel(list, "财务数据", request, response);
        return null;
    }


}
